using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AfterCaveStory
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        public static Game1 Self;

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        World world;

        public Game1()
        {
            Self = this;
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {

            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            
            world = new World(0.5f);

            Quote personagem = new Quote(Content.Load<Texture2D>("personagens"), new Rectangle(0, 0, 32, 32), 0.2f);
            personagem.isStatic = false;
            //personagem.drawCollisionBounds = true;
            personagem.setarPontoDeReferencia(Objeto2D.PontoDeReferencia.CENTRO);
            world.createObject(personagem);


            for(int i = 0; i < 30; i++)
            {

                Platform plataforma = new Platform(Content.Load<Texture2D>("platform"), new Rectangle(0, 0, 32, 32), 0.2f);
                plataforma.y = 300;
                plataforma.x = 16 + (i * 32);
                //plataforma.drawCollisionBounds = true;
                plataforma.setarPontoDeReferencia(Objeto2D.PontoDeReferencia.CENTRO);
                world.createObject(plataforma);
            }
        }

        protected override void UnloadContent()
        {
          
        }

        protected override void Update(GameTime gameTime)
        {
            Controller.Update(gameTime);
            world.update();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

                world.draw(gameTime, spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
